import Vue from 'vue'
import VueRouter from 'vue-router'






// import Login from './components/Login.vue'
const Login = () =>
    import( /* webpackChunkName: "login_home_welcome" */ '../components/login.vue')
// import Home from './components/Home.vue'
const Home = () =>
    import( /* webpackChunkName: "login_home_welcome" */ '../components/home.vue')
// import Welcome from './components/Welcome.vue'
const Welcome = () =>
    import( /* webpackChunkName: "login_home_welcome" */ '../components/welcome.vue')

// import Users from './components/user/Users.vue'
const Users = () =>
    import( /* webpackChunkName: "Users_Rights_Roles" */ '../components/user/users.vue')
// import Rights from './components/power/Rights.vue'
// const Rights = () =>
//     import ( /* webpackChunkName: "Users_Rights_Roles" */ '../components/power/rights.vue')
// import Roles from './components/power/Roles.vue'
const Roles = () =>
    import( /* webpackChunkName: "Users_Rights_Roles" */ '../components/power/roles.vue')




const Activity = () =>
    import( /* webpackChunkName: "Order_Report" */ '../components/activity/activity.vue')

const Signup = () =>
    import(/* webpackChunkName: "Signup" */ '../components/signup.vue')

Vue.use(VueRouter)

const routes = [

]

const router = new VueRouter({
    routes: [
        { path: '/', redirect: '/login' },
        { path: '/signup', component: Signup },
        { path: '/login', component: Login },
        {
            path: '/home',
            component: Home,
            redirect: '/welcome',
            children: [{
                path: '/welcome',
                component: Welcome
            }, {
                path: '/users',
                component: Users
            },

                , {
                path: '/roles',
                component: Roles
            },

            {
                path: '/activity',
                component: Activity
            }]
        }
    ]
})

//导航守卫
router.beforeEach((to, from, next) => {
    //to 访问路径
    //from 代表从个路径来
    //next 放行

    //注册和登录页面可以放行
    if (to.path == '/login') return next()
    if (to.path == '/signup') return next()
    //获取token
    const tokenStr = window.sessionStorage.getItem('token')
    if (!tokenStr) return next('/login')
    next()
})

export default router